Disabling HSTS for localhost using a browser extension

 
 
  • Gérald Barré
 
Http Strict Transport Security (HSTS) is a security mechanism that instructs the browser to automatically redirect http requests to https before sending a request to the server. When you are developing a web application, you should disable HSTS for localhost. This is because enabling HSTS on localhost has implications for other applications. For instance, some applications start a local web server and… [read more]

Using Mutex<T> to synchronize access to a shared resource

 
 
  • Gérald Barré
When you need to access a shared resource, you can use the lock statement or a synchronization primitive such as a Mutex to synchronize access to the resource. However, it's easy to forget it in complex code. When you need to synchronize access to a single resource, you can use a var obj = new object(); var value = 42; lock (obj) { // You need to ensure you use lock everywhere you access the shared… [read more]

Waiting for a ManualResetEventSlim to be set asynchronously

 
 
  • Gérald Barré
ManualResetEventSlim represents a thread synchronization event that, when signaled, must be reset manually. This is a common synchronization primitive. However, it doesn't expose a method to wait asynchronously. Hopefully, it's not too complicated to create an extension method using ThreadPool.RegisterWaitForSingleObject and TaskCompletionSource. static class Extensions { public static Task WaitAsync(this… [read more]

How to export user aliases from Microsoft Entra using PowerShell

 
 
  • Gérald Barré
Microsoft Graph is a REST API that allows you to interact with Microsoft 365 services. You can use it to automate tasks such as creating users, updating their properties, or exporting data. In this post, I'll show you how to export user email addresses and aliases from Microsoft Entra using PowerShell. First, you need to install the Microsoft.Graph module: Install-Module Microsoft.Graph -Scope CurrentUser… [read more]

Useful resources to write Roslyn Analyzers

 
 
  • Gérald Barré
Roslyn analyzers and source generators are useful but it's not easy to start writing them. The documentation is not at the same level as .NET or ASP.NET Core. There are some good resources on the internet. In this post, I share some resources to help you write Roslyn analyzers and source generators. View Syntax tree and IOperation tree When you write a Roslyn analyzer, you need to understand the syntax… [read more]

Create a bootable USB drive for Windows Server

 
 
  • Gérald Barré
The Windows Server image contains a .wim file which is bigger than 4GB. This is a problem because FAT32 does not support files bigger than 4GB. To solve this problem, we need to split the .wim file into smaller files. This can be done with the dism command. The following script extracts the content of the ISO file, splits the .wim file, formats the USB drive, and copies the files to the USB drive. # TODO… [read more]